AuthenticationManager is used to compare
● enteredPassword with the
● storedPassword in UserDetails Object (that was returned by UserDetailsService)
AuthenticationManager
● is called with Authentication Object as Input Parameter that contains enteredUsername and enteredPassword
● calls UserDetailsService with enteredUsername
● from UserDetailsService it gets UserDetails Object with storedPassword and authorities
● compares enteredPassword with storedPassword
● If passwords match User is considered Authenticated and AuthenticationManager returns Authentication Object with
○ storedUsername
○ storedPassword
○ authorities (also taken from UserDetails Object)
○ authenticated = true
Returned Authentication Object is accepted by the code that called AuthenticationManager. That calling code can now
● store Authentication Object into Context/Session
● return JWT token
At the end of the day UserDetails and Authenticate Objects might contain same data: Username, Password, Authorities.
But it is the Authenticate Object from which Spring Security will use Authorities to control access to Restricted Resources.
Since Authenticate Object also has Boolean authenticated which must be true for Spring to even look at Authorities.
UserDetails Object as DTO was just used as a temporary storage for Username, Password and Authorities as they make
their way from Database into Authenticate Object.
But UserDetails Object can also contain some additional User data that are not used for Authorization and will not be
transferred to Authenticate Object. In that case it makes sense to have them both inside Context.